package org.bonorsoft.modules.dingding.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.bonorsoft.common.dingapi.DingdingUser;
import org.bonorsoft.modules.dingding.entity.Params;
import org.bonorsoft.modules.dingding.entity.SysDingUser;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;

import java.util.List;

/**
 * @Description: 钉钉用户
 * @Author: WilliamYe
 * @Date:   2020-11-13
 * @Version: V1.0
 */
public interface SysDingUserMapper extends BaseMapper<SysDingUser> {

    @Select("select * from  sys_user  where userId = #{userId} and active = 1")
    SysDingUser getUserById(String userId);

    IPage<SysDingUser> selectUser(Page<SysDingUser> page,
                                  @Param("sysUser") SysDingUser sysUser,
                                  @Param("params") Params params,
                                  @Param("dataSql") String sql);

    @Select("SELECT userid,telephone,job_number,title,email,org_email,work_place,remark,dept_id_list,extension,hired_date,active,real_authed,senior,admin,boss,update_by,update_time,unionid,name,avatar,state_code,mobile,hide_mobile " +
            "FROM SYS_USER " +
            "WHERE dept_id_list = #{deptId} " +
            "OR instr(','||dept_id_list||',',','||#{deptId}||',')<>0")
    List<SysDingUser> selectInDeptUser(String deptId);

    IPage<SysDingUser> pageByConditions(Page<SysDingUser> page,
                                        @Param("sysUser") SysDingUser sysDingUser,
                                        @Param("roleId") String roleId,
                                        @Param("dataSql") String sql);

    List<String> getAllMenuUser(Long menuId);

    @Select("select u.userid from sys_user u left join sys_user_role ur on u.userid = ur.user_id where ur.id = #{roleId}")
    List<String> getAllRoleUser(Integer roleId);

    @Update("UPDATE sys_user SET dept_id = #{deptId} where userid = #{userId}")
    void updateUserDepart(String userId, Long deptId);

}
